package com.logic.landseaserver.models.unrent.ws;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.logic.common.enums.HttpCodeEnum;
import com.logic.common.util.CommonResult;
import com.logic.common.util.CommonResultMap;
import com.logic.landseaserver.common.LandeaConstants.CheckType;
import com.logic.landseaserver.common.exception.LandseaException;
import com.logic.landseaserver.common.util.LoggerHelper;
import com.logic.landseaserver.models.unrent.service.UnRentService;
import com.logic.landseaserver.ws.dto.CheckListDTO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 *
 * 项目名称：system-server</br>
 * 类名称：UnRentRest</br>
 * 类描述：退租</br>
 * 创建人：Aaron</br>
 * 创建时间：2017年8月22日 下午5:22:43</br>
 * 
 * @version 1.0
 *
 */
@Path("/unrent")
@Api(value = "退租unRent")
public class UnRentRest
{
    private static final Logger LOGGER = LoggerFactory.getLogger(UnRentRest.class);
    
    @Autowired
    private UnRentService unRentService;
    
    @POST
    @Path("/saveUnRentCheckList")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "保存退租交割信息")
    public Response saveUnRentCheckList(@ApiParam(value = "param", required = true) CheckListDTO checkListDTO)
    {
        CommonResultMap map = new CommonResultMap();
        try
        {
            checkListDTO.setCheckType(CheckType.UN_RENT);;
            unRentService.saveUnRentCheckList(checkListDTO);
            map.setResult(CommonResult.SUCCESS);
        }
        catch (LandseaException e)
        {
            LoggerHelper.handleException(LOGGER, "saveCheckList", e, map);
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @POST
    @Path("/getUnRentCheckList/{contractId}")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "查询退租交割信息")
    public Response getUnRentCheckList(@ApiParam(value = "param", required = true) @PathParam("contractId") Integer contractId,
                                       @ApiParam(value = "param", required = true) @QueryParam("oprType") String oprType)
    {
        CommonResultMap map = new CommonResultMap();
        try
        {
            CheckListDTO CheckListDTO  = unRentService.getUnRentCheckList(contractId,oprType);
            map.setData(CheckListDTO);
            map.setResult(CommonResult.SUCCESS);
        }
        catch (LandseaException e)
        {
            LoggerHelper.handleException(LOGGER, "getUnRentCheckList", e, map);
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
}
